/*
 * @Description: ------------ fileDescription -----------
 * @Author: snows_l snows_l@163.com
 * @Date: 2024-08-16 21:12:54
 * @LastEditors: snows_l snows_l@163.com
 * @LastEditTime: 2025-08-10 16:50:09
 * @FilePath: /BLOG/public/comm/main.js
 */
// 光标效果 配置
// window.custorEffect = new cursoreffects.textFlag({ text: 'snows_l', color: '#41BCE3' }); // 气泡光标
// 销毁光标
// cursoreffects.destroy();

// rgb颜色转Hex颜色
function rgbToHex(r, g, b) {
  let hexs = [r.toString(16), g.toString(16), b.toString(16)];
  for (let i = 0; i < 3; i++) {
    if (hexs[i].length == 1) {
      hexs[i] = `0${hexs[i]}`;
    }
  }
  return `#${hexs.join('')}`;
}

// 产生随机背景色
function getRandomColor() {
  let r = Math.floor(Math.random() * 256);
  let g = Math.floor(Math.random() * 256);
  let b = Math.floor(Math.random() * 256);
  return rgbToHex(r, g, b);
}

// 点击特效
document.addEventListener('click', e => {
  const cis = [
    '平和 +1',
    '自由 +1',
    '平等 +1',
    '爱国 +1',
    '敬业 +1',
    '诚信 +1',
    '友善 +1',
    '健健康康 +1',
    '升职 +1',
    '加薪 +1',
    '准点下班 +1',
    '逃离这满是世俗的生活 +1',
    'snows_l',
    '冬七',
    '年过百万 +1',
    '暴富 +1',
    '财务自由 +1',
    '幸福感 +1',
    '幸福 +1',
    '成功 +1',
    '财富自由 +1',
    '财源滚滚 +1',
    '财源广进 +1',
    '小得盈满 +1',
    '知足常乐 +1',
    '不求大富大贵 但求健健康康',
    '不忘初心  方得始终',
    '内向 -1',
    '不想被束缚 自由自在地去追求',
    '不计较  做自己',
    '就活这一次 下次不来了'
  ];
  /**
   * @description: 创建
   */
  const id = new Date().getTime();
  const color = getRandomColor();
  const text = cis[Math.floor(Math.random() * cis.length)];
  const el = document.createElement('div');
  const viewWidth = document.body.clientWidth;
  el.textContent = text;
  el.id = `snows_l_${id}`;
  el.style.color = color;
  el.style.fontSize = '16px';
  el.style.lineHeight = '16px';
  el.style.userSelect = 'none';
  el.style.transition = 'all 2s';
  el.style.pointerEvents = 'none';
  el.style.position = 'absolute';
  el.style.whiteSpace = 'nowrap';
  el.style.padding = '0px 10px';
  el.style.display = 'flex';
  el.style.alignItems = 'center';
  document.body.appendChild(el);

  const contentWidth = el.offsetWidth;
  el.style.left = `${e.clientX + contentWidth > viewWidth ? viewWidth - contentWidth - 5 : e.clientX - 10}px`;
  el.style.top = `${e.clientY - 20}px`;

  // 创建一个新的 style 标签
  var style = document.createElement('style');
  style.innerHTML = `
    #${'snows_l_' + id}::before {
        display: block;
        content: "";
        width: 3px;
        height: 12px;
        background-color: ${color};
        margin-right: 5px;
        border-radius: 2px;
    }
`;
  document.head.appendChild(style);

  setTimeout(() => {
    el.style.opacity = '0';
    el.style.transform = 'translateY(-80px)';
    setTimeout(() => {
      el.remove();
      style.remove();
    }, 1200);
  }, 150);
});
